﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VOL.Core.Utilities;
using VOL.Smartmanufacturing.DTO.ProductManagement;
using VOL.Smartmanufacturing;
using VOL.Smartmanufacturing.Infrastructure;
using VOL.Smartmanufacturing.IServices.ProductManagement;
using VOL.Entity.DomainModels;
using System.Collections.Generic;

namespace VOL.WebApi.Controllers.Smartmanufacturing
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaintenanceController : ControllerBase
    {
        private readonly IMaintenanceServices _maintenanceServices;

        public MaintenanceController(IMaintenanceServices maintenanceServices)
        {
            _maintenanceServices = maintenanceServices;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="maintenance"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> AddMaintenance([FromBody] Entity.DomainModels.Maintenance maintenance)
        {
            var result = await _maintenanceServices.AddMaintenance(maintenance);
            var webResponseContent = WebResponseContent.Instance.OK("添加成功", result);
            return webResponseContent;
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> DelMaintenance([FromBody]string ids)
        {
            var result = await _maintenanceServices.DelMaintenance(ids);
            var webResponseContent = WebResponseContent.Instance.OK("删除成功", result);
            return webResponseContent;
        }

        /// <summary>
        /// 回显
        /// </summary>
        /// <param name="maintenanceId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> GetMaintenanceById([FromQuery]int maintenanceId) 
        {
            var result = await _maintenanceServices.GetMaintenanceById(maintenanceId);
            var webResponseContent = WebResponseContent.Instance.OK("回显成功", result);
            return webResponseContent;
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="maintenance"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> UpdateMaintenance([FromBody] Entity.DomainModels.Maintenance maintenance) 
        {
            var result = await _maintenanceServices.UpdateMaintenance(maintenance);
            var webResponseContent = WebResponseContent.Instance.OK("编辑成功", result);
            return webResponseContent;
        }

        /// <summary>
        /// 显示/查询
        /// </summary>
        /// <param name="maintenanceDTO"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> GetAllMaintenance(MaintenanceDTO maintenanceDTO) 
        {
            var result = await _maintenanceServices.GetAllMaintenance(maintenanceDTO);
            var webResponseContent = WebResponseContent.Instance.OK("显示成功", result);
            return webResponseContent;
        }
        /// <summary>
        /// 获取所有工单台账的数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> GetAllTicketsLedger() 
        {
            var result = await _maintenanceServices.GetAllTicketsLedger();
            var webResponseContent = WebResponseContent.Instance.OK("显示成功", result);
            return webResponseContent;
        }
    }
}
